﻿using QDChat.Data;
using QDChat.Domain;
using QDChat.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QDChat.Data
{
    /// <summary>
    /// 消息管理
    /// </summary>
    public class DbMessage : IChatMessage
    {
        private static string TableName= "chat_message";

        public int Insert(Message model)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(model);
            }
            return model.Id;
        }

        public int SendMsg(Message model)
        {
            return Insert(model);
        }

        public List<Message> GetMsgList(int fromUid, int toUid, int page, int pageSize)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<Message>(page, pageSize, $"select * from {TableName} where (fromUid={fromUid} and toUid={toUid}) or (fromUid={toUid} and toUid={fromUid}) order by id desc");
            }
        }
    }
}